# 处理压缩文件
import os
import PDF_Process
import XLS_Process
import IMAGE_Process

src_dicname = './txt/' # 解压后的源文件夹
target_dicname = './TAR/' # 目标文件夹
wrong = './wrong_txt/' # 错误文件
log = './wrong_txt/' # 错误日志

def zip():
    image_time = 0
    src = './txt'
    list1 = os.listdir(src)
    # 文件夹
    for i in list1:
        try:
            print(i)
            list = os.listdir(src + '/' + i)
            # 文件夹内的项目
            for j in list:
                try:
                    print(j)
                    # 对文件内容进行处理
                    type = os.path.splitext(j)[1]
                    if type == ".docx" or type == ".doc":
                        '''
                        对doc没有进行处理
                        '''
                        continue
                    elif type == '.pdf':
                        # 参数i，是当前文件所处文件夹的名字
                        PDF_Process.fun(os.path.basename(j),i)
                        continue
                    elif type == ".jpg" or type == ".png" or type == ".jpeg":
                        image_time = image_time + 1
                        IMAGE_Process.fun(os.path.basename(j), image_time,i)
                        continue
                    elif type == ".xls" or type == ".xlsx":
                        if (type == '.xlsx'):
                            XLS_Process.fun(os.path.basename(j),i)
                        if (type == '.xls'):
                            XLS_Process.fun2(os.path.basename(j),i)
                        continue

                except NotADirectoryError as e:
                    print(i + " not a directoty")
        except NotADirectoryError as e:
            print(i + " not a directoty")
if __name__ == '__main__':
    zip()

